﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_SMS_DelMsg_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_SMS_DelMsg_V2];
GO
CREATE PROCEDURE [dbo].[sproc_SMS_DelMsg_V2]
    @msgIds		xml
    
/*

============================================================
功能:    短消息删除
参数:
    @msgids                     nvarchar,        :    消息ID字符串
    

============================================================

*/

AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;

-- get all the messaged to be deleted
/*
 * XML format:
 * <messages>
 *  <m id="" />
 * </messages>
 */
DECLARE @tmp TABLE 
(
    MsgID int NOT NULL
);
INSERT INTO @tmp(MsgID)
    SELECT X.m.value(N'@id', 'int')
    FROM @msgIds.nodes(N'/messages/m') X(m);

BEGIN TRANSACTION;

DELETE R FROM dbo.UDS_SMS_Receiver R INNER JOIN @tmp T ON R.MsgID = T.MsgID;
DELETE M FROM dbo.UDS_SMS_Msg M INNER JOIN @tmp T ON M.[ID] = T.MsgID;

COMMIT TRANSACTION;

END
GO
